onOptionsItemSelected

Deprecated

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override. Each MenuProvider then provides a consistent, optionally Lifecycle-aware, and modular way to handle menu item selection for the menu items created by that provider. Replace usages of this method with one or more calls to addMenuProvider in your Activity's onCreate method, delegating menu item selection to the individual MenuProvider that created the menu items you wish to handle.

This hook is called whenever an item in your options menu is selected. The default implementation simply returns false to have the normal processing happen (calling the item's Runnable or sending a message to its Handler as appropriate). You can use this method for any items for which you would like to do processing without those other facilities.

Derived classes should call through to the base class for it to perform the default menu handling.

Return

boolean Return false to allow normal menu processing to proceed, true to consume it here.

Parameters

item

The menu item that was selected.

See also